package com.ruoyi.web.controller.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.web.controller.tool.JsonResult;
import com.ruoyi.web.controller.tool.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JingfeiZhiliu;
import com.ruoyi.system.service.IJingfeiZhiliuService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-07-29
 */
@Controller
@RequestMapping("/system/zhiliu")
public class JingfeiZhiliuController extends BaseController
{
    private String prefix = "system/zhiliu";

    @Autowired
    private IJingfeiZhiliuService jingfeiZhiliuService;

    @RequiresPermissions("system:zhiliu:view")
    @GetMapping()
    public String zhiliu()
    {
        return prefix + "/zhiliu";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:zhiliu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JingfeiZhiliu jingfeiZhiliu)
    {
        startPage();
        List<JingfeiZhiliu> list = jingfeiZhiliuService.selectJingfeiZhiliuList(jingfeiZhiliu);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:zhiliu:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JingfeiZhiliu jingfeiZhiliu)
    {
        List<JingfeiZhiliu> list = jingfeiZhiliuService.selectJingfeiZhiliuList(jingfeiZhiliu);
        ExcelUtil<JingfeiZhiliu> util = new ExcelUtil<JingfeiZhiliu>(JingfeiZhiliu.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:zhiliu:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JingfeiZhiliu jingfeiZhiliu)
    {
        return toAjax(jingfeiZhiliuService.insertJingfeiZhiliu(jingfeiZhiliu));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:zhiliu:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JingfeiZhiliu jingfeiZhiliu = jingfeiZhiliuService.selectJingfeiZhiliuById(id);
        mmap.put("jingfeiZhiliu", jingfeiZhiliu);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:zhiliu:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JingfeiZhiliu jingfeiZhiliu)
    {
        return toAjax(jingfeiZhiliuService.updateJingfeiZhiliu(jingfeiZhiliu));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:zhiliu:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jingfeiZhiliuService.deleteJingfeiZhiliuByIds(ids));
    }


    @PostMapping("/JingfeiZhiliuList")
    @ResponseBody
    public TableDataInfo JingfeiZhiliuList(@RequestParam("deptid") String deptid,@RequestParam("name") String name)
    {
        startPage();
        List<Map<String,Object>> list = jingfeiZhiliuService.JingfeizhiliuList(deptid,name);
        return getDataTable(list);
    }

    @PostMapping("/findZhiliuByTuikuanjiluId")
    @ResponseBody
    public JsonResult<?> findZhiliuByTuikuanjiluId(@RequestParam("tuikuanjiluid")String tuikuanjiluid, @RequestParam("xingming")String xingming, @RequestParam("deptname")String deptname)
    {
        try{
            List<Map<String,Object>> list = jingfeiZhiliuService.findZhiliuByTuikuanjiluId(tuikuanjiluid,xingming,deptname);
            return JsonResult.getSuccessResult(list);
        } catch (Exception e){
            return JsonResult.getErrorResult("根据退款记录查询滞留经费失败");
        }
    }

}
